#include <iostream>
#include <unordered_map>
#include <string>
#include<vector>
#include <algorithm>
using namespace std;
bool cmp(pair<string, int>& p1, pair<string, int>& p2)
{
    return p1.second > p2.second;
}
int main()
{
    vector<pair<string, int>> ret;
    unordered_map<string, int> pos;
    string name;
    int ans = 0;
    while (cin >> name && name != "end")
    {
        if (pos.count(name))
        {
            ret[pos[name]].second++;
        }
        else {
            pos[name] = ans++;
            ret.push_back({ name,1 });
        }
    }
    
    sort(ret.begin(), ret.end(), cmp);
    for (auto p : ret)
    {
        cout << p.first << ' ' << p.second << endl;
    }
    return 0;
}